﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class UserGUI : MonoBehaviour {
    private IUserAction action;
    bool isFirst = true;
    GUIStyle white;
    GUIStyle black;

    // Use this for initialization
    void Start () {
        action = Director.getInstance().current as IUserAction;
        black = new GUIStyle("button");
        black.fontSize = 20;
        white = new GUIStyle();
        white.fontSize = 20;
        white.fontStyle = FontStyle.Bold;
        white.normal.textColor = Color.white;
        white.alignment = TextAnchor.UpperCenter;
    }

    private void OnGUI()
    {
        if (action.getGameState() == GameState.FUNISH)
        {
            GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 150, 200, 100), action.getScore() >= 30 ? "你赢了" : "你输了", white);
            if(GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height / 2 - 50, 120, 40), "重来", black))
            {
                SceneManager.LoadScene("DiskAttack");
            }
            return;
        }
        Rect rect = new Rect(Screen.width / 2 - 100, 0, 200, 40);
        Rect rect2 = new Rect(Screen.width / 2 - 45, 60, 120, 40);

        if (Input.GetButtonDown("Fire1") && action.getGameState() != GameState.PAUSE)
        {
            Vector3 pos = Input.mousePosition;
            action.hit(pos);
        }

        if (!isFirst)
        {
            GUI.Label(rect, "你的分数: " + action.getScore().ToString(), white);
        }
        else
        {
            GUIStyle blackLabel = new GUIStyle();
            blackLabel.fontSize = 16;
            blackLabel.normal.textColor = Color.white;
            GUI.Label(new Rect(Screen.width / 2 - 250, 120, 500, 200), "本游戏共有3轮，每轮会出现10个飞碟\n击中白色得1分\n击中灰色得2分\n击中黑色得4分\n得到30分胜利", blackLabel);
        }

        if (action.getGameState() == GameState.RUNNING && GUI.Button(rect2, "暂停", black))
        {
            action.setGameState(GameState.PAUSE);
        }
        else if(action.getGameState() == GameState.PAUSE && GUI.Button(rect2, "继续", black))
        {
            action.setGameState(GameState.RUNNING);
        }

        if (isFirst && GUI.Button(rect2, "开始", black))
        {
            isFirst = false;
            action.setGameState(GameState.ROUND_START);
        }

        if(!isFirst && action.getGameState() == GameState.ROUND_FINISH && GUI.Button(rect2, "下一关", black))
        {
            action.setGameState(GameState.ROUND_START);
        }
    }
}
